var productList = {
    needLoadMore: false,
    pageSize: 10,
    pageNum: 1,
    pageSize_product: 20,
    pageNum_product: 1,
    storageStr : "",
    inputSearch: function () {
        $(".history-count").hide();
        //搜索每次先清空
        $("#product-shellkm-list").html("");
        productList.pageNum = 1;
        //根据关键字查询知识列表
        productList.api_queryKnoledgeList();
    },
	bindEvent: function () {
    	$(".next-operation").unbind().on("click", function () {
			summer.closeWin();
		});
        /**
         * 绑定取消按钮点击事件
         */
        $("#product-search-word").unbind().on("click", function () {
            $(".history-count").hide();
            if("searchSOEM"==window.sessionStorage.searchType){
                $(".product-knowledge").css("display", "block");
                $("#search-search").css("display", "none");
            }else if("searchWorthdoc"==window.sessionStorage.searchType){
                $(".product-knowledge").css("display", "block");
                $("#search-search").css("display", "none");
            }else if("searchProdcut"==window.sessionStorage.searchType){
                $("#product-div").css("display", "block");
                $("#search-search").css("display", "none");
			}else if("search"==window.sessionStorage.searchType){
                productList.inputSearch();
			}else if("industry"==window.sessionStorage.searchType){
                $("#productListRtn").click();
			}
        });
        /**
         * 绑定搜索框清空按钮点击事件
         */
        $(".search_result_on_closed").unbind().on("click", function () {
            //清空搜索框
            $("#search_on_input").val("");
        });
        /**
         * 绑定返回按钮点击事件
         */
        $("#productListRtn").unbind().on("click", function () {
			common.hideLoading();
            window.sessionStorage.setItem("kc_pkid", "");
			window.sessionStorage.setItem("frist_pkid", "");
            $("#search_on_input").val("");
            window.sessionStorage.searchKey = "";
            //返回
            var searchKeyNotBackFlag = window.sessionStorage.searchKeyNotBackFlag;
        	/*if(searchKeyNotBackFlag != "false"){
        		window.history.back(-1);
        	}*/
            //记录跳转之前的页面路由，用于返回
            var currentURL = window.location.href;
            var thisPageBackRout = "";
            switch(currentURL.split("#")[1]){
            	// case "productListSearchByInput":
            	// 	thisPageBackRout = "#productList/searchProdcut";
            	// 	break;
            	case "productList/searchProdcut":
            		thisPageBackRout = "#home"; 
            		break;
            	case "knowledgeSearchByInput":
            		thisPageBackRout = "#productList/searchWorthdoc"; 
            		break;
            	case "productList/searchWorthdoc":
            		thisPageBackRout = "#home"; 
            		break;
        		case "productList/search":
            		thisPageBackRout = "#home"; 
            		break;
        		case "productList/industry":
            		thisPageBackRout = "#" + window.sessionStorage.productListPageFromRout; 
            		break;
        		case "productList/type1":
            		thisPageBackRout = "#industryEquip"; 
            		break;
        		case "productList/searchFromCompetList":
            		thisPageBackRout = "#competList"; 
            		break;
				case "productList/searchSOEM":
					thisPageBackRout="#home";
					break;
				case "soemListSearchByInput":
					thisPageBackRout="#productList/searchSOEM";
					break;
				case "productList/mine":
					thisPageBackRout="#home";
					break;
            		
            		
            }
                window.location.href = thisPageBackRout;
        });
		//点击搜索历史
        function selectHistory() {
			$(".key_item").unbind().on("click",function () {
				var key = $(this).children(".historyItem").attr("key");
				$("#search_on_input").val(key);
				productList.storageStr = key;
				window.sessionStorage.searchKey = key;
                productList.inputSearch();
				$(".history-count").hide();
			});
		}
        //获取焦点事件
        $("#search_on_input").focus(function(){
            var localStorageGetKeywords = window.localStorage.getItem("keywords");
            if(localStorageGetKeywords && localStorageGetKeywords.length>0){
            	var keywordArray = JSON.parse(localStorageGetKeywords);
	            if (keywordArray && keywordArray.length >0) {
	            	$(".history-count").show();
	            	keywordArray.reverse();
	            	var html = "";
	                for (var i = 0; i < keywordArray.length; i++) {
	                   html +='<li class="key_item"><img src="images/history-search.png" class="search-img"/>'
	                  		+ '<div class="keyword-div historyItem" key ="'+keywordArray[i]+'">'+keywordArray[i] +'</div>'
	                  		+ '<div class="history-delect" key ="'+keywordArray[i]+'"><img src="images/history-delect.png"/></div></li>';
	                }
	               $("#historyList").html(html);
	               selectHistory();
	            } else {
	               
	               $(".history-count").hide();
	            }
            }else{
            	$(".history-count").hide();
            }
        });
        ////搜索历史删除
        //$(".history-delect").unbind().on("click",function () {
        //	var key = $(this).attr("key");
        //	var localStorageGetKeywords = window.localStorage.getItem("keywords");
        //	if(localStorageGetKeywords && localStorageGetKeywords.length>0){
        //
	     //       var keywordArray = JSON.parse(localStorageGetKeywords);
	     //       for (var i = 0; i < keywordArray.length; i++) {
	     //           if (key ==keywordArray[i] ) {
	     //               keywordArray.splice(i, 1);
	     //           }
	     //       }
	     //       window.localStorage.setItem("keywords", JSON.stringify(keywordArray));
	     //       var html = "";
	     //       for (var i = 0; i < keywordArray.length; i++) {
	     //          html +='<li><img src="images/history-search.png" class="search-img"/>'
	     //         		+ '<div class="keyword-div historyItem" key ="'+keywordArray[i]+'">'+keywordArray[i] +'</div>'
	     //         		+ '<div class="history-delect" key ="'+keywordArray[i]+'"><img src="images/history-delect.png"/></div></li>';
	     //       }
	     //      $("#historyList").html(html);
			//	//点击搜索历史
			//	selectHistory();
        //  	}else{
        //  		$(".history-count").hide();
        //  	}
        //
        //});
        //清空搜索历史
        $(".history-clear-btn").unbind().on("click",function () {
        	 window.localStorage.setItem("keywords", "");
        	 $(".history-count").hide();
        });
        //搜索历史关闭
        $(".history-closed").unbind().on("click",function () {
        	$(".history-count").hide();
        });
        
        /**
         * 绑定价值文档里面行业按钮点击事件
         */
        $("#indestryList").unbind().on("click",function(){
        	var isViewIndestry = $("#indestry-click").find("i").attr("class");
        	if("up"==isViewIndestry){
        		$(".value-document-footer").hide();
        		//按钮变颜色和箭头方向
            	$("#indestry-click").attr("class","product-down");
            	$("#indestry-click").find("i").attr("class","down");
            	//隐藏行业对应的内容
            	$("#industryHtmlDiv").css("display","none");
            	//显示之前显示内容
            	$("#product-list-table").css("display","");
            	$("#knowledgeProductFirstNav").css("display","");
            	$("#productSecondNav").css("display","");
				$("#selected-keyword").css("display","");
        	}else{
        		//初始化都没有选上
        		//$(".is-select").find("i").attr("class","no-select");
        		if($(".industryli").length==0){
        			//查询数据库拼接行业数据
            		productList.initIndustry();
        		}
        		$(".value-document-footer").show();
        		//行业按钮变颜色和箭头方向
            	$("#indestry-click").attr("class","product-down product-red");
            	$("#indestry-click").find("i").attr("class","up");
            	//产品按钮变颜色和箭头方向
            	$("#product-click").attr("class","product-down");
            	$("#product-click").find("i").attr("class","down");
            	//显示行业对应的内容
            	$("#industryHtmlDiv").css("display","");
            	//隐藏行业对应的内容
            	$("#productHtmlDiv").css("display","none");
            	//隐藏之前显示内容
            	$("#product-list-table").css("display","none");
            	$("#knowledgeProductFirstNav").css("display","none");
            	$("#productSecondNav").css("display","none");
				$("#selected-keyword").css("display","none");
            	
            	//绑定重置事件
	    		$("#resetButton").unbind().on("click",function(){
	    			if("up"==$("#indestry-click").find("i").attr("class")){
	    				window.sessionStorage.setItem("industryNameBySearch","");
	    				$(".industryi").removeClass("yes-select").removeClass("industryi").addClass("no-select");
	    			}
	    			if("up"==$("#product-click").find("i").attr("class")){
	    				window.sessionStorage.setItem("productNameBySearch","");  
	    				$(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
	    			}
	    		});
	    		
	    		//行业确定事件
	    		$("#confirmButton").unbind().on("click",function(){
	    			$(".value-document-footer").hide();
	    			productList.getSelectedName();
	    			productList.pageNum = 1;
	    			productList.api_queryKnoledgeList();
	    			//按钮变颜色和箭头方向
	            	$("#indestry-click").attr("class","product-down");;
	            	$("#indestry-click").find("i").attr("class","down");
	            	//隐藏行业对应的内容
	            	$("#industryHtmlDiv").css("display","none");
	            	//显示之前显示内容
	            	$("#product-list-table").css("display","");
	            	$("#knowledgeProductFirstNav").css("display","");
	            	$("#productSecondNav").css("display","");
					$("#selected-keyword").css("display","");
	            	//$(".secondKC").css("color","black");
	            	//去掉选中样式
	            	//$(".is-select").find("i").attr("class","no-select");
	    		});
        	}        	
        });
        /**
         * 绑定价值文档里面产品按钮点击事件
         */
        $(".productListForClick").unbind().on("click",function(){
        	var isViewProduct = $("#product-click").find("i").attr("class");
        	if("up"==isViewProduct){
        		//隐藏操作
        		$(".value-document-footer").hide();
        		//按钮变颜色和箭头方向
            	$(".product-down").attr("class","product-down");
            	$(".product-down").find("i").attr("class","down");
            	//隐藏产品对应的内容
            	$("#productHtmlDiv").css("display","none");
            	//显示之前显示内容
            	$("#product-list-table").css("display","");
            	$("#knowledgeProductFirstNav").css("display","");
            	$("#productSecondNav").css("display","");
				$("#selected-keyword").css("display","");
        	}else{
        		//初始化都没有选上
        		//$(".is-select").find("i").attr("class","no-select");
        		if($(".productli").length==0){
        			productList.pageNum_product = 1;
            		//查询数据库拼接产品数据
                	productList.productListFromWorthdoc();
                	$(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
        		}
        		//显示操作
        		$(".value-document-footer").show();
        		//产品按钮变颜色和箭头方向
            	$(".product-down").attr("class","product-down product-red");
            	$(".product-down").find("i").attr("class","up");
            	//行业按钮变颜色和箭头方向
            	$("#indestry-click").attr("class","product-down");
            	$("#indestry-click").find("i").attr("class","down");
            	//显示产品对应的内容
            	$("#productHtmlDiv").css("display","");
            	//隐藏行业内容
            	$("#industryHtmlDiv").css("display","none");
            	//隐藏之前显示内容
            	$("#product-list-table").css("display","none");
            	$("#knowledgeProductFirstNav").css("display","none");
            	$("#productSecondNav").css("display","none");
				$("#selected-keyword").css("display","none");
            	
            	//绑定重置事件
	    		$("#resetButton").unbind().on("click",function(){
	    			if("up"==$("#indestry-click").find("i").attr("class")){
	    				window.sessionStorage.setItem("industryNameBySearch","");
	    				$(".industryi").removeClass("yes-select").removeClass("industryi").addClass("no-select");
	    			}
	    			if("up"==$("#product-click").find("i").attr("class") || "up"==$("#product-product-click").find("i").attr("class")){
	    				window.sessionStorage.setItem("productNameBySearch","");  
	    				$(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
	    			}
	    		});
	    		
	    		//绑定产品确定事件
	    		$("#confirmButton").unbind().on("click",function(){
	    			$(".value-document-footer").hide();
	    			productList.getSelectedName();
	    			productList.pageNum = 1;
	    			productList.api_queryKnoledgeList();
	    			
	    			//按钮变颜色和箭头方向
	            	$("#indestry-click").attr("class","product-down");;
	            	$("#indestry-click").find("i").attr("class","down");
	            	//隐藏行业对应的内容
	            	$("#industryHtmlDiv").css("display","none");
	    			//价值文档按钮变颜色和箭头方向
	            	$("#product-click").attr("class","product-down");
	            	$("#product-click").find("i").attr("class","down");
	            	//产品里面的按钮变颜色和箭头方向
	            	$("#product-product-click").attr("class","product-down");;
	            	$("#product-product-click").find("i").attr("class","down");
	            	//隐藏产品对应的内容
	            	$("#productHtmlDiv").css("display","none");
	            	//显示之前显示内容
	            	$("#product-list-table").css("display","");
	            	$("#knowledgeProductFirstNav").css("display","");
	            	$("#productSecondNav").css("display","");

	            	//$(".secondKC").css("color","black");
	            	//去掉选中样式
	            	//$(".is-select").find("i").attr("class","no-select");
	    		});
        	}  
        });
        /**
         * 绑定价值文档、S-OEM里面搜索按钮点击事件
         */
        $("#search-click").unbind().on("click",function(){
			// if("searchSOEM"==window.sessionStorage.searchType){
			// 	// window.location.href="#soemListSearchByInput";
            //
			// }else{
        		// // window.location.href="#knowledgeSearchByInput";
			// }
			//隐藏一级标题
			$(".product-knowledge").hide();
			//显示搜索框
			$("#search-search").css("display", "block");
        });


        /**
         * 绑定产品里面搜索按钮点击事件
         */
        $("#product-search-click").unbind().on("click",function(){
        	//页面内逻辑跳转
        	// window.location.href="#productListSearchByInput";
            //隐藏一级标题
            $("#product-div").hide();
            //显示搜索框
            $("#search-search").css("display", "block");
        });
    },
	textChange:function (e) {
    	var input=$("#search_on_input").val();
        productList.storageStr = input;
        window.sessionStorage.searchKey = input;
        productList.inputSearch();
    },
    productSearch: function () {
        window.sessionStorage.setItem("industryNameBySearch", "");
        window.sessionStorage.setItem("productNameBySearch", "");
        $(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
        window.sessionStorage.setItem("kc_pkid", window.sessionStorage.getItem("frist_pkid"));
        //隐藏列表
        $("#product-list-table").css("top", "4.8rem");
        $("#product-list-table").show();
        //隐藏二级标题
        $("#productSecondNav").hide();
        //隐藏行业列表
        $("#industryHtmlDiv").hide();
        //隐藏产品列表
        $("#productHtmlDiv").hide();
        //隐藏行业和产品对应的操作按钮
        $(".value-document-footer").hide();
        //按钮变颜色和箭头方向
        $("#product-product-click").attr("class", "product-down");
        $("#product-product-click").find("i").attr("class", "down");

        //隐藏一级标题
        $("#product-div").hide();
        //显示搜索框
        $("#search-search").css("display", "block");
        productList.api_queryFirstKnoledgeCategoryForPk();
    },
	WorthDocSearch: function () {
        window.sessionStorage.setItem("industryNameBySearch", "");
        window.sessionStorage.setItem("productNameBySearch", "");
        $(".industryi").removeClass("yes-select").removeClass("industryi").addClass("no-select");
        $(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
        window.sessionStorage.setItem("kc_pkid", window.sessionStorage.getItem("frist_pkid"));
        //隐藏列表
        //$("#product-list-table").hide();
        $("#product-list-table").css("top", "4.8rem");
        $("#product-list-table").show();
        //隐藏二级标题
        $("#productSecondNav").hide();
        //隐藏行业列表
        $("#industryHtmlDiv").hide();
        //隐藏产品列表
        $("#productHtmlDiv").hide();
        //隐藏行业和产品对应的操作按钮
        $(".value-document-footer").hide();
        //改变行业和产品对应的样式
        $("#indestry-click").attr("class", "product-down");
        ;
        $("#indestry-click").find("i").attr("class", "down");
        $("#product-click").attr("class", "product-down");
        ;
        $("#product-click").find("i").attr("class", "down");

        //隐藏一级标题
        $(".product-knowledge").hide();
        //显示搜索框
        $("#search-search").css("display", "block");
        productList.api_queryFirstKnoledgeCategoryForPk();
    },
	SoemSearch: function () {
        window.sessionStorage.setItem("industryNameBySearch", "");
        window.sessionStorage.setItem("productNameBySearch", "");
        $(".industryi").removeClass("yes-select").removeClass("industryi").addClass("no-select");
        $(".producti").removeClass("yes-select").removeClass("producti").addClass("no-select");
        window.sessionStorage.setItem("kc_pkid", window.sessionStorage.getItem("frist_pkid"));
        //隐藏列表
        //$("#product-list-table").hide();
        //$("#product-list-table").css("top","4.8rem");
        $("#product-list-table").show();
        ////隐藏二级标题
        //$("#productSecondNav").hide();
        //隐藏行业列表
        $("#industryHtmlDiv").hide();
        //隐藏产品列表
        $("#productHtmlDiv").hide();
        //隐藏行业和产品对应的操作按钮
        $(".value-document-footer").hide();
        //改变行业和产品对应的样式
        $("#indestry-click").attr("class", "product-down");
        $("#indestry-click").find("i").attr("class", "down");
        $("#product-click").attr("class", "product-down");
        $("#product-click").find("i").attr("class", "down");

        //隐藏一级标题
        $(".product-knowledge").hide();
        //显示搜索框
        $("#search-search").css("display", "block");
    }, /**
     * 绑定路由
     */
    bindRout: function () {
    	//首页
		Path.map("#home").to(function () {
			//记录状态
			common.loadPageDiv("html/index.html",false,true);
		});
        //工序列表
        Path.map("#industryEquip").to(function () {
            //记录状态
            common.loadPageDiv("html/industryEquip.html", true,true);
        });
        Path.map("#competList").to(function () {
            //记录状态
            common.loadPageDiv("html/competList.html",false,true);
        });
        
        //查询结果列表点解进入页面
		Path.map("#productList/:status").to(function () {
			var type = this.params['status'];
			window.sessionStorage.searchType = type;
			common.loadPageDiv("html/productList.html", true,true);
		});

        //选择详情页面
        Path.map("#detail").to(function () {
            //记录状态
            common.loadPageDiv("html/detail.html", true);
            //window.history.replaceState({}, "title", "#home")
        });
        // //产品点击搜索后的触发事件
        // Path.map("#productListSearchByInput").to(function () {
        //     this.productSearch();
        // });

        //价值文档点击搜索后的触发事件
        // Path.map("#knowledgeSearchByInput").to(function () {
        //     this.WorthDocSearch();
        // });

		//SOEM点击搜索后的触发事件
		// Path.map("#soemListSearchByInput").to(function () {
         //    this.SoemSearch();
		// });
        Path.listen();

    },
    /**
     * 初始化
     */
    init: function () {
        $("#product-list-ul").html("");
        //判断最近搜索点击跳转传过来的数据是否有值
        var searchKey = window.sessionStorage.getItem("searchKey");
        if (searchKey == undefined || searchKey == "") {
            //$("#search_on_input").focus();
            //productList.api_queryKnoledgeList();
        } else {
            $("#search_on_input").val(searchKey);
        }
        productList.storageStr = $("#search_on_input").val();
    },
    /**
     * API请求--查询知识列表
     */
    api_queryKnoledgeList: function () {
        var url = "/kmpublish/App/queryKmpublishPoJoLike";
        var functionParam = {
            "pk_user": window.localStorage.userid,
            "likeName": window.sessionStorage.searchKey,
            "industrykey": window.sessionStorage.industryNameBySearch,
            "productkey": window.sessionStorage.productNameBySearch,            
            "kmType": window.sessionStorage.getItem("kc_pkid"),
            "pageSize": productList.pageSize,
            "pageNum": productList.pageNum
        }
        common.interfaceAjaxFunction(url, functionParam, productList.queryKnoledgeListCallBack, true);
    },
    /**
     * API请求--查询所有一级类别
     */
    api_queryFirstKnoledgeCategory: function () {
        var param = {
            "pk_user": window.localStorage.userid
        };
        var url = "/PCKnowledgeCategoryEntity/selectFisrt";
        common.interfaceAjaxFunction(url, param, productList.queryFirstKnoledgeCategoryCallBack, true,"",false);
    },
    /**
     * API请求--查询一级类别下的所有二级类别
     * @param firstKnoledgeCategoryPk 一级类别PK
     */
    api_querySecondKnoledgeCategory: function (firstKnoledgeCategoryPk) {
        var url = "/PCKnowledgeCategoryEntity/selectSecond";
        var functionParam = {
            "fw_parent": firstKnoledgeCategoryPk
        };
        common.interfaceAjaxFunction(url, functionParam, productList.querySecondKnoledgeCategoryCallBack, true);
    },
    /**
     * 查询知识列表回调
     */
    queryKnoledgeListCallBack: function (res) {
        if (res.status != 0) {
        	//给出信息提示
			common.show_error(res.message,"product-shellkm-list");
        } else {
        	if(productList.pageNum==1){
        		 $("#product-shellkm-list").html("");
        	}
            var dataArray = res["data"];
            if (dataArray.length == 0) {
            	$("#product-shellkm-list").css("min-height", $(window).height() - $(".header").height());
                if ($("#" + window.sessionStorage.currentShownSysPanelId  + " .product-list").length > 0) {
                    common.showTip("已加载全部知识信息");
                } else {
                    common.show_nodata("没有更多知识信息", "product-shellkm-list");
                }
            }
            if (productList.storageStr.length != 0&&productList.storageStr.trim()!='') {
                var localStorageGetKeywords = window.localStorage.getItem("keywords");
                if(localStorageGetKeywords && localStorageGetKeywords.length>0){
                
	                var keywordArray = JSON.parse(localStorageGetKeywords);
	                if (keywordArray) {
	                    for (var i = 0; i < keywordArray.length; i++) {
	                        if (common.strTrim(keywordArray[i]) == common.strTrim(productList.storageStr)) {
	                            keywordArray.splice(i, 1);
	                        }
	                    }
	                    if (keywordArray.length >= 4) {
	                        keywordArray.shift();
	                    }
	                    keywordArray.push(common.strTrim(productList.storageStr));
	                    window.localStorage.setItem("keywords", JSON.stringify(keywordArray));
	                    //console.log("用户最近查询的关键词: ", keywordArray);
	                } else {
	                    keywordArray = new Array;
	                    keywordArray.push(common.strTrim(productList.storageStr));
	                    window.localStorage.setItem("keywords", JSON.stringify(keywordArray));
	                    //console.log("用户最近查询的关键词: ", keywordArray);
	                }
                }else{
                	var keywordArray = new Array;
                    keywordArray.push(common.strTrim(productList.storageStr));
                    window.localStorage.setItem("keywords", JSON.stringify(keywordArray));
                }
            }
            //拼接代码
            for (var i = 0; i < dataArray.length; i++) {
                var dic = dataArray[i];
				var attachment_count=dic["attachment_count"];
                var publish_key = dic["publish_key"];
                var keywords = publish_key.split(",");
                var soruceTime = dic["publish_time"];
                var k_name = dic["publish_title"];
                var knowledge_category_name = dic["knowledge_category_name"];
                var pk_km_publish = dic["pk_km_publish"];
                var terSource = dic["ter"];
                var terStr = "";
                if (k_name != undefined && productList.DataLength(k_name) > 32) {
                    k_name = k_name.substring(0, 31) + "...";
                }
                if (parseInt(terSource) > 9999) {
                    terStr = "9999+";
                } else {
                    terStr = parseInt(terSource);
                }
                var html = '<div class="product-list" pkid=' + pk_km_publish + '>' +
					'<div class="product-list-left">'+
                    '<div class="product-list-h1">' +
                    '<div class="product-title">' + k_name + '</div>' +
                    
                    '</div>' +
                    '<div class="product-list-count">' +
                    '<div class="product-list-count">';
                
                
                html +=
                	'<div class="product-time">' + dic["publish_time"] + '</div>' +  //时间
                    '<div class="product-collection">' +
                    '<span class="fr" id="fr_'+pk_km_publish+'">' + terStr + '</span>' + '<i class="pro-clooect-icon">' + '</i>' +
                    '</div>' +
					'</div>'+
                    '</div>';
				if(attachment_count>0){
                	html += '</div><div class="product-list-attachment"><img id="right-icon'+pk_km_publish+'" class="product-list-right-icon" src="images/wd2.png"><span class="product-list-circle">'+attachment_count+'</span></div>';
				}else{
					html += '</div><div class="product-list-attachment"><img id="right-icon'+pk_km_publish+'" class="product-list-right-icon" src="images/wd1.png"></div>';
				}
                //更新UI
                $("#product-shellkm-list").append(html);
            }
            //高度设定
        	$("#product-shellkm-list").css("min-height", $("#product-list-table").height() + 1);
        	
            //初始化上拉加载下拉刷新控件
            common.initIscroll("product-list-table", productList.pullDownCallBack, productList.pullUpCallBack);
           
            /**
             * 绑定跳转详情页面点击事件
             */
            $(".product-list-left").unbind().on("click", function () {
                $("#search_on_input").blur();
                window.sessionStorage.setItem("product_detail_id", $(this).parent().attr("pkid"));
                //记录跳转之前的页面路由，用于返回
                var currentURL = window.location.href;
                window.sessionStorage.detailPageFromRout = currentURL.split("#")[1];
                window.location.href = "#detail";
            });
			/**
			 * 获取附件
			 */
			$(".product-list-attachment").unbind().on("click", function () {
				//$("#search_on_input").blur();
				var attachmentNum=$(this).children(".product-list-circle").text();
				if(attachmentNum>0){
					var pk_knowledge=$(this).parent().attr("pkid");
					var url = "/kmpublish/App/queryAttByPK";
					var functionParam = {
						"pk_publish": pk_knowledge,
						"pk_user": window.localStorage.userid
					};
					common.interfaceAjaxFunction(url, functionParam, productList.queryAttachmentCallBack, true);
				}
			});
        }
    },
	queryAttachmentCallBack:function(res){
		if(res.status!=0){
			common.showTip(res.message);
		}else{
			var attachmentArray=res["data"][0].achementList_oth;
			console.log(attachmentArray);
			$("#attachmentList_List").html("");
			if(attachmentArray&&attachmentArray.length>0){
				for(var i=0;i<attachmentArray.length;i++){
					var att=attachmentArray[i];
					var fileType=att.filename.split(".").pop();
					var imageurl = "images/";
					switch (fileType.toLowerCase()) {
						case "docx":
						case "doc":
							imageurl += "word";
							break;
						case "pdf":
							imageurl += "pdf";
							break;
						case "xlsx":
						case "xls":
							imageurl += "excel";
							break;
						case "pptx":
						case "ppt":
							imageurl += "ppt";
							break;
						case "mp4":
							imageurl += "mp4";
							break;
						default:
							imageurl += "other";
							break;
					}
					imageurl += ".png";
					var attHtml='<div class="attachment_item" dataurl="' + att.fileurl + '" fileName= "' + att.fname + '" fileType="'+fileType+'" pk_attachment= "' + att.pk_attachment +'" thisFileSize="'+att.filesize+'">' +
						'<div class="attachment-icon"><img src='+imageurl+'></div>'+
						'<div class="attachment-content">'+
						'<div class="attachment-title">'+att.fname+'</div>'+
						'<div class="attachment-size">'+att.filesize+'</div>'+
						'<div id="skill"><div><span class="expand html5" id="'+att.pk_attachment+'" style="display:none;"></span></div></div>'+
						'</div>'+
						'</div>';
					$("#attachmentList_List").append(attHtml);
				}
				//common.showPopLayer("attachmentList_productList");
				//初始化上拉加载下拉刷新控件
				common.initIscrollBody("attachmentList_productList_iscroll");
				$("#assign").show();
				productList.initAttachmentDownload();
				//关闭
				$(".point").unbind().on("click",function(){
					$(".mask").hide();
				});
			}
		}
	},

	initAttachmentDownload:function(){
		$(".attachment_item").unbind().on("click", function () {
			var url = $(this).attr("dataurl");
			var type = $(this).attr("fileType");
			var fileName = $(this).attr("fileName")+ "." + type;
			var id =$(this).attr("pk_attachment");
			var filePath = "shellkm"+"/";
			fileName = id +","+fileName;
			$("#"+id).addClass(id);

			var fileSize = $(this).attr("thisFileSize");

			//判断文件是否已经存在。
			var flag = $file.exists({
				path : filePath,
				file : fileName
			});

			if(flag!="false"){
				//重新记录一次
				productList.recordCurrentUserAttachDownloadFiles(fileName,filePath,id,type,url,fileSize);
				productList.openfile(type,filePath,fileName);
				return false;
			}
			url = common.contextPath() + "/file/appdownloadFile/" + id;
			productList.downloadDocx(url,filePath,fileName);
		});
	},
	/**
     * 查询所有一级类别回调
     */
    queryFirstKnoledgeCategoryCallBack: function (res) {
        if (res.status != 0) {
            common.showTip(res.message);
        } else {
            var dataArray = res["data"];
			$("#product-list-ul").html("");
            $("#product-list-ul").append('<li class="firstKC" categoryPk="'+window.sessionStorage.getItem("frist_pkid")+'" style="color: orange;">全部<p class="product-line"></p></li>');
            for (var i = 0; i < dataArray.length; i++) {
                var html = "";
                var dic = dataArray[i];
                var categoryName = dic["knowledge_category_name"];
                var categoryPk = dic["pk_knowledge_category"];
                html += '<li class="firstKC" categoryPk="' + categoryPk + '">' + categoryName + '</li>';
                $("#product-list-ul").append(html);
            }
            /**
             * 绑定一级类别点击事件
             */
            $(".firstKC").unbind().on("click", function () {
            	if($(this).children().hasClass("product-line")){
            		return false;
            	}
            	$(".pro-secound").html("");
                $(".pro-secound").find("a").css("color", "black");
                productList.topicSwitchTo(this);
                window.sessionStorage.setItem("kc_pkid", $(this).attr("categoryPk"));
                $("#product-shellkm-list").html("");
                productList.pageNum = 1;
                //查询选定一级类别的所有知识列表
                productList.api_queryKnoledgeList();
                //查询选定一级类别的二级类别
                productList.api_querySecondKnoledgeCategory(window.sessionStorage.getItem("kc_pkid"));
            });
        }
        //宽度
        var allLiObjLength = 0;
        $(".product-list-ul li").each(function () {
            allLiObjLength += $(this).outerWidth(true);
        });
        allLiObjLength += 40;
        //设定width
        $("#product-list-ul").width(allLiObjLength + "px");
        //横向滚动条初始化isocroll
        common.initIscrollBodyHorizontal("productFirstNav");//horizontal:横向滚动，默认纵向
    },
    /**
     * 查询一级类别下的所有二级类别回调
     */
    querySecondKnoledgeCategoryCallBack: function (res) {
        if (res.status != 0) {
        	//如果二级类别失败，则隐藏二级类别块
        	productList.showSecondKnoledgeCategoryBlock(false);
        } else {
            var dataArray = res["data"];
            if (dataArray.length == 0) {//如果二级类别为空，则隐藏二级类别块
                productList.showSecondKnoledgeCategoryBlock(false);
            } else {//如果二级类别有数据，则显示二级类别快
                productList.showSecondKnoledgeCategoryBlock(true);
				$(".pro-secound").html("");
				var firstCategoryPk=window.sessionStorage.getItem("kc_pkid");
				if("searchSOEM"==window.sessionStorage.searchType){
					firstCategoryPk=window.sessionStorage.getItem("frist_pkid");
				}
                $(".pro-secound").append('<a class="secondKC" categoryPk="'+firstCategoryPk+'" style="color: orange;">全部</a>');
                for (var i = 0; i < dataArray.length; i++) {
                    var dic = dataArray[i];
                    var html = "";
                    var categoryName = dic["knowledge_category_name"];
                    var categoryPk = dic["pk_knowledge_category"];
                    html += '<a class="secondKC" categoryPk=' + categoryPk + '>' + categoryName + '</a>';
                    $(".pro-secound").append(html);
                }
                /*
                var searchType = window.sessionStorage.searchType;
                if(searchType!="" && searchType != "industry"){
                	$("#productSecondNav").css("top","3.8rem");
            		$("#product-list-table").css("top","5.8rem");
                }*/
            }
            /**
             * 绑定二级类别点击事件
             */
            $(".secondKC").unbind().on("click", function () {
                $(".pro-secound").find("a").css("color", "black");
                $(this).css("color", "orange");
                window.sessionStorage.setItem("kc_pkid", $(this).attr("categoryPk"));
                productList.getSelectedName();
                productList.pageNum = 1;
                //查询选定二级类别的知识列表
                productList.api_queryKnoledgeList();
            });

            //宽度
            var allLiObjLength = 0;
            $(".pro-secound a").each(function () {
            	//根据每个字体的长度计算
            	var eachFontWidth = $(this).css("fontSize").replace("px","");
            	//单个字体的长度，字体个数增加1，因为CSS中有个margin：0，0.5rem，左右多出1个字
                allLiObjLength += eachFontWidth * ($(this).html().length + 1);
            });
            allLiObjLength += 80;//两边各40像素
            //设定width
            $(".pro-secound").width(allLiObjLength + "px");
            //横向滚动条初始化isocroll
            common.initIscrollBodyHorizontal("productSecondNav");//horizontal:横向滚动，默认纵向
        }
    },
    /**
	 * 调用ajax取得行业的信息内容
	 */
	initIndustry:function(){
		//调用根据用户查询所有行业信息-带是否设置状态，判断是否已经设置
		var param = {
				"level":2
			};
		var ajaxUrl = "/PCIndustryChart/queryBycondition";
		common.interfaceAjaxFunction(ajaxUrl,param,this.queryAllIndestryByUserSucess,true,"",false);//不记录缓存
	},
	/**
     * 查询行业信息
     */
    queryAllIndestryByUserSucess:function(json){
    	//成功时候
    	if(json.status == "0"){
    		if(json.data.length > 0){
    			//把数据保存在sessionStorge中，用于下
	    		window.sessionStorage.allIndestryJson = JSON.stringify(json);
	    		//显示行业内容
	    		var jsonData = json.data;
	    		//循环加入数据
		    	$("#industryHtml").html("");
		    	for(var i=0;i<jsonData.length;i++){
		    		//当前数据
		    		var industryRow = jsonData[i];
		    		//拼接数据
		    		var industryStr = '<li class="is-select industryli"><span class="'+industryRow.cate_name+'">'+ industryRow.cate_name + '</span><i class="no-select"></i></li>';
		    		//加入页面中去
		    		$("#industryHtml").append(industryStr);
		    	}
		    	//初始化，isocroll
				common.initIscrollBody("industryHtmlDiv");
				//绑定选择行业选中事件
	    		$(".industryli").unbind().on("click",function(){
	    			var isSelect = $(this).find("i").attr("class");
	    			if("no-select"==isSelect){
	    				$(this).find("i").attr("class","yes-select industryi");
	    			}else{
	    				$(this).find("i").attr("class","no-select");
	    			}
	    		});
	    		
    		}else{
    			//没有行业信息
    			common.show_nodata("当前无行业信息","industryHtml");
                //隐藏操作按钮
		    	$(".value-document-footer").hide();
    		}
    	}else{
    		//给出信息提示
    		common.show_error(json.message,"industryHtml");
    	}
    },
	 /**
     * 获取选中的行业和产品
     */
    getSelectedName:function(){
    	window.sessionStorage.setItem("industryNameBySearch","");
        window.sessionStorage.setItem("productNameBySearch","");  
    	var industryNum = $("i.industryi").prev();
		var industrySelectValue = "";
		var keywordHtml="";
		$("#keyword-body").html("");
		for(var i=0; i<industryNum.length; i++){
			if(industrySelectValue==""){
				industrySelectValue = industryNum[i].className;
			}else{
				industrySelectValue = industrySelectValue+";"+industryNum[i].className;
			}
			keywordHtml=keywordHtml+'<div class="knowledge-item knowledge-grey"><span class="select-key-word">'+industryNum[i].className+'</span><img class="close-icon" src="images/search-closed.png"></div>';
		}
		var productNum = $("i.producti").prev();
		var productSelectValue = "";
		for(var i=0; i<productNum.length; i++){
			if(productSelectValue==""){
				productSelectValue = productNum[i].className;
			}else{
				productSelectValue = productSelectValue+";"+productNum[i].className;
			}
			keywordHtml=keywordHtml+'<div class="knowledge-item knowledge-grey"><span class="select-key-word">'+productNum[i].className+'</span><img class="close-icon" src="images/search-closed.png"></div>';
		}
		window.sessionStorage.setItem("industryNameBySearch",industrySelectValue);
		window.sessionStorage.setItem("productNameBySearch",productSelectValue);
		$("#keyword-body").html(keywordHtml);
		this.displayKeyWord(industrySelectValue, productSelectValue);
    },
	displayKeyWord:function (industrySelectValue,productSelectValue){
		if(industrySelectValue.length>0||productSelectValue.length>0){
			$("#selected-keyword").css("display","block");
			$("#productSecondNav").css("top","5.6rem");
			$("#product-list-table").css("top","7.6rem");
			//宽度
			var allLiObjLength = 0;
			$("#keyword-body div").each(function () {
				allLiObjLength += $(this).outerWidth(true);
			});
			allLiObjLength += 40;
			//设定width
			$("#keyword-body").width(allLiObjLength + "px");
			common.initIscrollBodyHorizontal("selected-keyword");//horizontal:横向滚动，默认纵向
			$(".knowledge-item").unbind().on("click",function(){
				var keyword=$(this).find("span").html();
				$(this).remove();
				var removeItem = $(".yes-select");
				for(var a= 0;a<removeItem.length;a++){
					if(keyword==removeItem[a].previousSibling.className){
						removeItem[a].className='no-select';
					}
				}
				if(industrySelectValue.indexOf(keyword + ";") >= 0){
					industrySelectValue=industrySelectValue.replace(keyword + ";","");
				}else{
					industrySelectValue=industrySelectValue.replace(keyword ,"");
				}
				if(productSelectValue.indexOf(keyword + ";") >= 0){
					productSelectValue=productSelectValue.replace(keyword + ";","");
				}else{
					productSelectValue=productSelectValue.replace(keyword ,"");
				}
				if(industrySelectValue.length<=0&&productSelectValue.length<=0){
					$("#selected-keyword").css("display","none");
					$("#productSecondNav").css("top","4.0rem");
					$("#product-list-table").css("top","6.0rem");
				}
				window.sessionStorage.setItem("industryNameBySearch",industrySelectValue);
				window.sessionStorage.setItem("productNameBySearch",productSelectValue);
				productList.pageNum = 1;
				productList.api_queryKnoledgeList();
			});
		}else if("search"!=window.sessionStorage.searchType){
			$("#selected-keyword").css("display","none");
			$("#productSecondNav").css("top","4.0rem");
			$("#product-list-table").css("top","6.0rem");
		}
	},
    /**
     * 调用ajax获取产品列表信息
     */
    productListFromWorthdoc:function(){
    	var ajaxUrl = "/pcBdproduct/queryProductPage";
    	var param = {
    		"type":"1",
            "pageSize": productList.pageSize_product,
            "pageNum": productList.pageNum_product
        }
		common.interfaceAjaxFunction(ajaxUrl,param,this.queryAllProductSucess,true,"",false);//不记录缓存
    },
    /**
     * 展示产品列表
     */
    queryAllProductSucess:function(json){
    	//成功时候
		if(json.status != "0"){
    		//给出信息提示
			common.show_error(json.message,"productHtmlDiv");
    	}else{
        	if(productList.pageNum_product==1){
        		 $("#productHtml").html("");
        	}	
            var dataArray = json["data"];
            if (dataArray.length == 0) {
                if ($("#productHtml").find("li").length > 0) {
                    common.showTip("已加载全部产品信息");
                } else {
                    common.show_nodata("没有更多产品信息", "productHtmlDiv");
                }
            }
    		if(json.data.length > 0){
    			//把数据保存在sessionStorge中，用于下
	    		window.sessionStorage.allIndestryJson = JSON.stringify(json);
	    		//显示行业内容
	    		var jsonData = json.data;
	    		//循环加入数据
		    	//$("#productHtml").html(""); 
		    	//显示操作按钮
		    	for(var i=0;i<jsonData.length;i++){
		    		//当前数据
		    		var industryRow = jsonData[i];
		    		//拼接数据
		    		var industryStr = '<li class="is-select productli"><span class="'+industryRow.product_name+'">'+ industryRow.product_name + '</span><i class="no-select"></i></li>';
		    		//加入页面中去
		    		$("#productHtml").append(industryStr);
		    	}
		    	
		        //初始化上拉加载下拉刷新控件
				common.initIscroll("productHtmlDiv", productList.pullDownCallBack, productList.pullUpCallBack,1);
				
		    	//绑定选择产品选中事件
	    		$(".productli").unbind().on("click",function(){
	    			var isSelect = $(this).find("i").attr("class");
	    			if("no-select"==isSelect){
	    				$(this).find("i").attr("class","yes-select producti");
	    			}else{
	    				$(this).find("i").attr("class","no-select");
	    			}
	    		});
    		}
    	}
    },
    /**
     * 上拉加载更多
     */
    pullUpCallBack: function () {
        //需要加载更多，在更新UI的时候走拼接, 而不是覆盖原来的
        var isViewProduct = $("#product-click").find("i").attr("class");
        var isViewPProduct = $("#product-product-click").find("i").attr("class");
        if(isViewProduct=="up" || isViewPProduct=="up"){
        	productList.pageNum_product += 1;
        	productList.productListFromWorthdoc();
        }else{
        	productList.pageNum += 1;
        	productList.api_queryKnoledgeList();
        }
    },
    /**
     * 下拉刷新
     */
    pullDownCallBack: function () {
        var isViewProduct = $("#product-click").find("i").attr("class");
        var isViewPProduct = $("#product-product-click").find("i").attr("class");
        if(isViewProduct=="up" || isViewPProduct=="up"){
        	productList.pageNum_product = 1;
        	productList.productListFromWorthdoc();
        }else{
        	productList.pageNum = 1;
        	//再次进入的时候的处理，防止缓存
			window.sessionStorage.kmpublishAppqueryKmpublishPoJoLike = "";
        	productList.api_queryKnoledgeList();
        }
    },
    /**
     * 切换分类更新分类UI
     */
    topicSwitchTo: function (currentTopic) {
        var ulTag = $("#product-list-ul");
        //点击标签的时候下面的横线移动和字体颜色切换
        ulTag.find("li").css('color', 'black');
        ulTag.find("p").remove();
        $(currentTopic).append('<p class="product-line"></p>');
        $(currentTopic).css('color', 'orange');
    },
    /**
     * 显示/隐藏二级类别块
     * @param showOrHide 显示或隐藏
     */
    showSecondKnoledgeCategoryBlock: function (showOrHide) {
        if (showOrHide == false) {//隐藏二级类别块
            $("#productSecondNav").css("display", "none");
            if("industry"==window.sessionStorage.searchType){
            	$("#product-list-table").css("top", "4.4rem");
            }else{
            	$("#product-list-table").css("top", "6.4rem");
            }
        } else {//显示二级类别快
            $("#productSecondNav").css("display", "block");
           
    		var productFirstNavDisplay = $("#productFirstNav").css("display");
			var keywordDivDisplay =$("#selected-keyword").css("display");
            if(productFirstNavDisplay == "none"&& keywordDivDisplay!="none"){
            	$("#productSecondNav").css("top","5.6rem");
         		$("#product-list-table").css("top","7.6rem");
            }else if(productFirstNavDisplay == "none"&& keywordDivDisplay=="none") {
				$("#productSecondNav").css("top","4.0rem");
				$("#product-list-table").css("top","6.0rem");
			}else{
            	$("#productSecondNav").css("top","6.4rem");
         		$("#product-list-table").css("top","8.4rem");
            }
        }
    },
    /**
     * 根据传入的字符串计算出长度
     * @param str 需要进行计算长度的字符串
     */
    DataLength: function (str) {
        var len = 0;
        if (str.match(/[^ -~]/g) == null) {
            len = str.length;
        }
        else {
            len = str.length + str.match(/[^ -~]/g).length;
        }
        return len;
    },
    
    /**
     * API请求--查询所有一级类别
     */
    api_queryFirstKnoledgeCategoryForPk: function () {
        var param = {
            "pk_user": window.localStorage.userid
        };
        var url = "/PCKnowledgeCategoryEntity/selectFisrt";
        common.interfaceAjaxFunction(url, param, productList.getSearchWorthdocPkCallBack, true);
    },
    
    getSearchWorthdocPkCallBack:function(res){
    	if (res.status != 0) {
    		common.showTip(res.message);
    	} else {
    		var dataArray = res["data"];
            for (var i = 0; i < dataArray.length; i++) {
            	var html = "";
                var dic = dataArray[i];
                var categoryName = dic["knowledge_category_name"];
                var categoryPk = dic["pk_knowledge_category"];
                if("价值文档"==categoryName && "searchWorthdoc"==window.sessionStorage.searchType){
                	productList.querySecondLeverType(categoryPk);
                	break;
                }
                if("产品"==categoryName && "searchProdcut"==window.sessionStorage.searchType){
                	productList.querySecondLeverType(categoryPk);
                	break;
                }
                
                if("行业图表"==categoryName && "industry"==window.sessionStorage.searchType){
                	productList.querySecondLeverType(categoryPk);
                	break;
                }

				if("S-OEM"==categoryName && "searchSOEM"==window.sessionStorage.searchType){
					productList.querySecondLeverType(categoryPk);
					break;
				}
            }
    	}
    },
    /**
     * 根据一级查二级
     */
    querySecondLeverType : function(categoryPk){
    	window.sessionStorage.setItem("kc_pkid", categoryPk);
    	window.sessionStorage.setItem("frist_pkid", categoryPk);
    	productList.api_querySecondKnoledgeCategory(categoryPk);
    	productList.storageStr = "";
        productList.api_queryKnoledgeList();
    },
    /**
     * each page
     */
    initialize: function () {
    	//标题设定
    	$("#pageTitle_productList").text(window.sessionStorage.pageTitle);
    	//看看有无返回键,false不显示
    	var searchKeyNotBackFlag = window.sessionStorage.searchKeyNotBackFlag;
    	if(searchKeyNotBackFlag == "false"){
    		$("#productListRtn").html("&nbsp;");
    	}else{
    		$("#productListRtn").show();
    	}
    	var searchType = window.sessionStorage.searchType;
    	if("search"==searchType){
            $("#product-search-word").html("搜索");
		}
    	if("searchWorthdoc"==searchType || "searchProdcut"==searchType||"searchSOEM"==searchType){
    		window.sessionStorage.setItem("industryNameBySearch","");
            window.sessionStorage.setItem("productNameBySearch",""); 
    		//筛选部分的处理
    		if("searchWorthdoc"==searchType||"searchSOEM"==searchType){
    			$(".product-knowledge").css("display", "block");
				$("#search-search").css("display", "none");
    		//}else if("searchSOEM"==searchType) {
				//$("#search-search").css("display", "block");
			}else{
				$(".product-knowledge-product").css("display", "block");
				$("#search-search").css("display", "none");
			}
    		$("#knowledgeProductFirstNav").css("display","");
    		$("#productFirstNav").css("display", "none");
    		//根据一级查询出相应的二级
    		productList.api_queryFirstKnoledgeCategoryForPk();
    	}else if("industry"==searchType){
    		$("#productFirstNav").css("display", "none");
        	$("#product-list-table").css("top","4.0rem");
    		//查询出产品的所有二级
    		productList.api_queryFirstKnoledgeCategoryForPk();
    	}else{
    		window.sessionStorage.setItem("frist_pkid", "");
    		window.sessionStorage.setItem("kc_pkid", "");
    		$(".product-knowledge").css("display", "none");
    		$("#knowledgeProductFirstNav").css("display","none");
    		$("#search-search").css("display", "block");
    		$("#productFirstNav").css("display", "block");
    		//查询出产品的所有一级
    		productList.api_queryFirstKnoledgeCategory();
    		//清空
    		$("#product-shellkm-list").html("");
            productList.pageNum = 1;
            //查询选定一级类别的所有知识列表
            productList.api_queryKnoledgeList();
            //查询选定一级类别的二级类别
            productList.api_querySecondKnoledgeCategory(window.sessionStorage.getItem("kc_pkid"));
    	}
	    //绑定事件
        productList.bindEvent();
        //绑定路由
        productList.bindRout();
        //初始化
        productList.init();
        //滚动
        var topSearchPartHeight = $(window).height() - $(".header").height() - $(".product-knowledge").height() - $(".value-document-footer").height();
        $("#industryHtmlDiv").height(topSearchPartHeight);
        $("#productHtmlDiv").height(topSearchPartHeight);
        $("#productHtml").css("min-height",$(window).height() - $(".header").height() - $(".product-knowledge").height() );
        $("#product-shellkm-list").css("min-height", $(window).height() - $(".header").height());
    },
	downloadCall: function (args) {
		var name = args.filename;
		var id = name.split(",")[0];
		$("#" + id).show();
		if (args.isfinish) {
			common.showTip("下载完成");
			$('.' + id).css('width', "70%");
			var path = args.filepath;
			type = name.split(".").pop();
			$("#" + id).removeClass(id);
			setTimeout(function () {
				$("#" + id).hide();
			}, 2000);
			//xiaz
			productList.recordCurrentUserAttachDownloadFiles(name, args.savePath, id, type, args.url, "");
			//最后打开文件
			$file.open({
				"filename": name,//文件全路径
				"filetype": type,
				"filepath": path
			});
		} else {
			var percent = parseInt(args.percent) * 0.75;
			console.log(args.percent + ",percent===" + percent);
			$('.' + id).css('width', percent + "%");
		}
	},
	errorFunction: function (res) {
		//common.showTip(res);
		alert(res);
	},

	openfile: function (filetype, filepath, filename) {
		$file.open({
			"filename": filename,//文件全路径
			"filetype": filetype,
			"filepath": filepath
		})
	},
	downloadDocx: function (url, filepath, filename) {
		//开始了
		var getNetworkInfo = JSON.parse($net.getNetworkInfo());
		// //判断是否为wifi连接，
		if (getNetworkInfo.Type == "Wifi" || getNetworkInfo.Type == "WiFi") {
			$file.download({
				"url": url,
				"locate": filepath,
				"filename": filename,
				"override": "true",
				"callback": "productList.downloadCall()",
				"error": "productList.errorFunction()"
			});
		} else {
			common.showConfirm("您未链接Wi-Fi，确定使用流量下载附件吗？", function () {
				$file.download({
					"url": url,
					"locate": filepath,
					"filename": filename,
					"override": "true",
					"callback": "productList.downloadCall()",
					"error": "productList.errorFunction()"
				});
			});

		}
	},
	//记录附件下载的公共函数
	recordCurrentUserAttachDownloadFiles: function (fileName, savePath, id, type, url, thisFileSize) {
		//当前年月日计算
		var myDate = new Date();
		//年
		var att_year = myDate.getFullYear();
		//获取当前月份
		var att_month = parseInt(myDate.getMonth()) + 1;
		//获取当前日
		var att_day = myDate.getDate();

		//文件大小
		var fileSize = 0;
		if (thisFileSize == "" || thisFileSize == undefined) {
			//下载的文件信息
			var savePathInfo = $file.getFileInfo(savePath);
			if (typeof(savePathInfo) == "string") {
				fileSize = common.strToJson(savePathInfo).size;
			} else {
				fileSize = savePathInfo.size;
			}
			fileSize = common.calcFileSize(fileSize);
		} else {
			fileSize = thisFileSize;
		}
		//保存当前信息到本地存储当中去
		var thisFileInfo = {
			"att_day": parseInt(att_day) < 10 ? "0" + att_day : att_day,
			"att_month": parseInt(att_month) < 10 ? "0" + att_month : att_month,
			"att_year": att_year,
			"filename": fileName,
			"filesize": fileSize,
			"fileurl": url,
			"fname": fileName.split(",")[1].substring(0, fileName.split(",")[1].lastIndexOf(".")),
			"pk_attachment": id,
			"pk_business": "",
			"upload_type": type
		};
		//取得当前的json串值
		var currentUserAttachDownloadFiles = common.strToJson(window.localStorage.currentUserAttachDownloadFiles);
		if (typeof(currentUserAttachDownloadFiles) == "undefined") {
			currentUserAttachDownloadFiles = [];
		}
		//从0开始
		var i = 0;
		for (i = 0; i < currentUserAttachDownloadFiles.length; i++) {
			console.log(currentUserAttachDownloadFiles[i].fname);
			if (thisFileInfo.pk_attachment == currentUserAttachDownloadFiles[i].pk_attachment) {
				console.log("已经存在");
				break;
			}
		}
		if (i == currentUserAttachDownloadFiles.length) {
			currentUserAttachDownloadFiles.push(thisFileInfo);
			//保存到本地
			window.localStorage.currentUserAttachDownloadFiles = JSON.stringify(currentUserAttachDownloadFiles);
		}
	}
};